package cc.geguo.dao;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

import cc.geguo.entity.Admin;
import cc.geguo.utils.JdbcUtils;

/**
 * 作者  Administrator
 * 时间  2017/2/17 13:10
 * 文件  StrutsLoginDemo
 * 描述  登录 读取
 */
public class AdminDao {
//	SELECT * FROM admin WHERE username = ? AND pwd = ?
	public Admin login(Admin admin){
		String sql = "SELECT * FROM admin WHERE username = ? AND pwd = ?";
		try {
			return JdbcUtils.getQuerrRunner()
					.query(sql,new BeanHandler<>(Admin.class),
							admin.getUserName(),
							admin.getPwd());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List<Admin> getAll() {
		String sql = "SELECT * FROM admin";
		try {
			return JdbcUtils.getQuerrRunner()
					.query(sql,new BeanListHandler<>(Admin.class));
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
}
